﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="detailandmed_v3_ettevotja", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(DetailandmedV3Ettevotja))]
    public class DetailandmedV3EttevotjaSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDetailandmedV3Ettevotja clazz;
        
        public DetailandmedV3EttevotjaSerializer(IDetailandmedV3Ettevotja clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ariregistri_kood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AriregistriKood))).ToString());
            Writer.WriteEndElement();
            if (clazz.Yldandmed!=null) {
                Writer.WriteStartElement("yldandmed");
                global::Xtee.Core.SerializationMetadata metaYldandmed = this.GetMetaData(clazz.Yldandmed);
                Writer.WriteTypeAttribute(metaYldandmed.TypeQualifiedName.Namespace, metaYldandmed.TypeQualifiedName.Name);
                metaYldandmed.NewSerializer(clazz.Yldandmed).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Isikuandmed!=null) {
                Writer.WriteStartElement("isikuandmed");
                global::Xtee.Core.SerializationMetadata metaIsikuandmed = this.GetMetaData(clazz.Isikuandmed);
                Writer.WriteTypeAttribute(metaIsikuandmed.TypeQualifiedName.Namespace, metaIsikuandmed.TypeQualifiedName.Name);
                metaIsikuandmed.NewSerializer(clazz.Isikuandmed).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.Kommertspandiandmed!=null) {
                Writer.WriteStartElement("kommertspandiandmed");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("detailandmed_kommertspant", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Kommertspandiandmed.Count);
                for (int x = 0; ((clazz.Kommertspandiandmed != null) 
                            && (x < clazz.Kommertspandiandmed.Count)); x = (x + 1)) {
                    if (clazz.Kommertspandiandmed[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaKommertspandiandmed = this.GetMetaData(clazz.Kommertspandiandmed[x]);
                        Writer.WriteTypeAttribute(metaKommertspandiandmed.TypeQualifiedName.Namespace, metaKommertspandiandmed.TypeQualifiedName.Name);
                        metaKommertspandiandmed.NewSerializer(clazz.Kommertspandiandmed[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.MenetlusesAvaldused!=null) {
                Writer.WriteStartElement("menetluses_avaldused");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("detailandmed_dokument", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.MenetlusesAvaldused.Count);
                for (int x = 0; ((clazz.MenetlusesAvaldused != null) 
                            && (x < clazz.MenetlusesAvaldused.Count)); x = (x + 1)) {
                    if (clazz.MenetlusesAvaldused[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaMenetlusesAvaldused = this.GetMetaData(clazz.MenetlusesAvaldused[x]);
                        Writer.WriteTypeAttribute(metaMenetlusesAvaldused.TypeQualifiedName.Namespace, metaMenetlusesAvaldused.TypeQualifiedName.Name);
                        metaMenetlusesAvaldused.NewSerializer(clazz.MenetlusesAvaldused[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ariregistri_kood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v3_ettevotja>ariregistri_kood");
                }
                clazz.AriregistriKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("ariregistri_kood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>detailandmed_v3_ettevotja>ariregistri_kood", Reader.LocalName);
            }
            if (Reader.LocalName=="yldandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v3_ettevotja>yldandmed");
                }
                global::Xtee.Core.SerializationMetadata metaYldandmed = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedv2Yldandmed>(Reader, "detailandmedv2_yldandmed", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Yldandmed = metaYldandmed.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedv2Yldandmed>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("yldandmed");
                    metaYldandmed.NewSerializer(clazz.Yldandmed).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="isikuandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v3_ettevotja>isikuandmed");
                }
                global::Xtee.Core.SerializationMetadata metaIsikuandmed = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV3Isikuandmed>(Reader, "detailandmed_v3_isikuandmed", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Isikuandmed = metaIsikuandmed.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedV3Isikuandmed>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("isikuandmed");
                    metaIsikuandmed.NewSerializer(clazz.Isikuandmed).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="kommertspandiandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v3_ettevotja>kommertspandiandmed");
                }
                clazz.Kommertspandiandmed = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedKommertspant>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("kommertspandiandmed");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_kommertspandiandmed>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaKommertspandiandmed = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedKommertspant>(Reader, "detailandmed_kommertspant", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedKommertspant item = metaKommertspandiandmed.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedKommertspant>();
                        clazz.Kommertspandiandmed.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaKommertspandiandmed.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="menetluses_avaldused") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_v3_ettevotja>menetluses_avaldused");
                }
                clazz.MenetlusesAvaldused = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedDokument>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("menetluses_avaldused");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_dokumendid>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaMenetlusesAvaldused = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedDokument>(Reader, "detailandmed_dokument", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedDokument item = metaMenetlusesAvaldused.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IDetailandmedDokument>();
                        clazz.MenetlusesAvaldused.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaMenetlusesAvaldused.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
